package org.spbsu.apco.common.utils;

import java.util.Random;

/**
 * User: Anton Ovchinnikov
 * Date: 12/23/12
 * Time: 11:36 PM
 */
public class BenchmarkUtils {

    private static long doBenchmarkIteration() {
      Random random = new Random();
      double result = random.nextDouble();
      for (int i = 0; i < 1000; i++) {
        result *= random.nextDouble();
      }
      return (long)result;
    }

    public static long getBenchmarkData() {
      int totalTime = 3000; // in milliseconds
      boolean toFinish = false;
      long iterationsDone = 0;
      long startTime = System.currentTimeMillis();
      while (!toFinish)
      {
        long iterationResult = doBenchmarkIteration();
        iterationsDone++;
        toFinish = (System.currentTimeMillis() - startTime >= totalTime);
      }
      return iterationsDone;
    }

}
